package im.run;

import jade.wrapper.AgentController;
import jade.wrapper.ControllerException;

public class Launcher {

	
	private static boolean createSniffer = true;
	private static int numContainer = 10;
	/**
	 * @param args
	 */
	
	public static void main(String[] args) {
        System.out.println(args.length + " argument/s");
        jade.core.Runtime rt0 = jade.core.Runtime.instance();
        
        jade.core.Profile mcProfile = new jade.core.ProfileImpl();
        jade.core.Profile mcProfile2 = new jade.core.ProfileImpl();
        jade.wrapper.AgentContainer mc = rt0.createMainContainer(mcProfile);
        jade.wrapper.AgentContainer mc2[] = new jade.wrapper.AgentContainer[numContainer];
        for(int i=0;i<numContainer;i++){
        	mc2[i] = rt0.createAgentContainer(new jade.core.ProfileImpl());
	        try {
				mc2[i].start();
			} catch (ControllerException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
        }
        // Create the Agents
        Object[] arguments = new Object[2];
        if (args.length == 2) {
            arguments[0] = args[0];
            arguments[1] = args[1];
        }
        else if (args.length == 3 && args[2].equals("-sniffer")) {
            arguments[0] = args[0];
            arguments[1] = args[1];
            createSniffer = true;
        }
        else if (args.length == 1 && args[0].equals("-sniffer")) {
            arguments = null;
            createSniffer = true;
        }
        else {
            arguments = null;
        }
        try {
        	AgentController RMA = 
        		mc.createNewAgent("RMA", "jade.tools.rma.rma", null);
        	RMA.start();
            jade.wrapper.AgentController sc =
            	mc.createNewAgent("SC", "im.agents.slachecker.SLAChecker", arguments);            
            sc.start();
           /* jade.wrapper.AgentController cm =
            	mc.createNewAgent("CM", "im.agents.contextmanager.ContextManager", arguments);*/
     

            jade.wrapper.AgentController monitor1 =
            	mc.createNewAgent("monitork", "im.agents.monitor.NodeMonitor", arguments);
            monitor1.start();
            
            jade.wrapper.AgentController a =
            	mc.createNewAgent("A", "im.agents.users.Requester", arguments);
            a.start();
            
            jade.wrapper.AgentController contextManager =
            	mc.createNewAgent("CM", "im.agents.contextmanager.ContextManager", arguments);
            	contextManager.start();
            	
            jade.wrapper.AgentController cm2[] = new AgentController[numContainer];
            for(int j=0;j<numContainer;j++){
                 cm2[j] = mc2[j].createNewAgent("CM"+j, 
                		 "im.agents.contextmanager.ContextManager", arguments);
                cm2[j].start();
            }
            
          jade.wrapper.AgentController monitor[] = new AgentController[numContainer];;
            for(int j=0;j<numContainer;j++){
                monitor[j] = mc2[j].createNewAgent("Monitor"+j, "im.agents.monitor.NodeMonitor", arguments);
               monitor[j].start();
           }
            	
            jade.wrapper.AgentController provider[] = new AgentController[5];
            for(int i1=0;i1<5;i1++){
            	provider[i1] = mc2[3].createNewAgent("provider"+i1+"1", "im.agents.service.ProviderImplA", arguments);
            	provider[i1].start();
            }
            
            for(int i1=0;i1<5;i1++){
            	provider[i1] = mc2[5].createNewAgent("provider"+i1+"2", "im.agents.service.ProviderImplB", arguments);
            	provider[i1].start();
            }
            
            jade.wrapper.AgentController requester[] = new AgentController[3];
            for(int i1=0;i1<3;i1++){
            	requester[i1] = mc2[7].createNewAgent("A"+i1+"1", "im.agents.users.Requester", arguments);
            	requester[i1].start();
            }
            
            for(int i1=0;i1<3;i1++){
            	requester[i1] = mc2[8].createNewAgent("A"+i1+"2", "im.agents.users.Requester", arguments);
            	requester[i1].start();
            }
            
            jade.wrapper.AgentController migrationManager =
            	mc2[9].createNewAgent("MM", "im.agents.migration.MigrationManager", arguments);
            	migrationManager.start();
          	
            jade.wrapper.AgentController contextRequester =
            	mc2[9].createNewAgent("ContextRequester", "im.agents.users.ContextRequester", arguments);
            	contextRequester.start();
        }
        
        catch (Exception e) {
            e.printStackTrace();
        }
        
        
    }
	
	
}
        


